added some development tools
[windows-sources.git] / developer / Samples / NET Standard / ParallelExtensionsExtras / TaskSchedulers / CurrentThreadTaskScheduler.cs
blobe773afa155f96f427a92bace4634722ddd56a127
1 //--------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // File: CurrentThreadTaskScheduler.cs
6 //
7 //--------------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Linq;
12 namespace System.Threading.Tasks.Schedulers
14 /// <summary>Provides a task scheduler that runs tasks on the current thread.</summary>
15 public sealed class CurrentThreadTaskScheduler : TaskScheduler
17 /// <summary>Runs the provided Task synchronously on the current thread.</summary>
18 /// <param name="task">The task to be executed.</param>
19 protected override void QueueTask(Task task)
21 TryExecuteTask(task);
24 /// <summary>Runs the provided Task synchronously on the current thread.</summary>
25 /// <param name="task">The task to be executed.</param>
26 /// <param name="taskWasPreviouslyQueued">Whether the Task was previously queued to the scheduler.</param>
27 /// <returns>True if the Task was successfully executed; otherwise, false.</returns>
28 protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
30 return TryExecuteTask(task);
33 /// <summary>Gets the Tasks currently scheduled to this scheduler.</summary>
34 /// <returns>An empty enumerable, as Tasks are never queued, only executed.</returns>
35 protected override IEnumerable<Task> GetScheduledTasks()
37 return Enumerable.Empty<Task>();
40 /// <summary>Gets the maximum degree of parallelism for this scheduler.</summary>
41 public override int MaximumConcurrencyLevel { get { return 1; } }